package cn.kai.ums.controller;

import cn.kai.ums.model.UmsUser;
import cn.kai.ums.service.UmsUserService;
import cn.kai.ums.tools.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("ums/v1/login")
public class LoginController {

    @Autowired
    private UmsUserService umsUserService;


    @PostMapping
    public JsonData login(@RequestBody UmsUser user, HttpServletResponse response){
        String token =umsUserService.checklogin(user.getUserName(),user.getUserPwd());
        if(token=="0"){
            return JsonData.buildError("账号或密码错误");
        }else {
            if(token=="-1"){
                return JsonData.buildError("用户已被禁用，请联系管理员.");
            }else {
                return JsonData.buildSuccess(token);
            }
        }
    }

}
